package com.ck.ck_back.controller;

import com.ck.ck_back.pojo.Comment;
import com.ck.ck_back.pojo.Result;
import com.ck.ck_back.service.commentservice;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/comment")
public class CommentComtroller {
    @Resource
    private commentservice commentserviceimpl;

    @PostMapping("/select")
    public Object select(int production_id){
        Object obj = commentserviceimpl.getall(production_id);
        if (obj != null){
            return Result.success(obj);
        }else {return Result.failure("null");}
    }

    @PostMapping("/insert")
    public Object insert(Comment comment){
        int result = commentserviceimpl.insert(comment);
        if (result == 1){
            return Result.success();
        }else if (result ==2){
            return Result.failure("失败");
        }else {return Result.failure("参数错误");}
    }

    //    删除评论，404参数为空，3无此评论，2删除失败，1成功
    @PostMapping("/delete")
    public Object delete(int comment_id){
        int result = commentserviceimpl.delete(comment_id);
        if (result == 1){
            return Result.success();
        }else if(result == 2){
            return Result.failure("修改失败");
        }else if(result == 3){
            return Result.failure("无此评论");
        }else {
            return Result.failure("参数错误");
        }
    }

}
